import java.util.Scanner;

public class TaxiPricingDemo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取用户输入的里程
        System.out.print("请输入行驶里程（公里）: ");
        double distance = scanner.nextDouble();

        // 读取用户输入的时间
        System.out.print("请输入时间（格式：HH:mm）: ");
        String timeInput = scanner.next();

        // 读取出租车类型
        System.out.print("请输入出租车类型（A/B）: ");
        String taxiType = scanner.next();

        try {
            // 获取对应时间段的计价策略
            PricingStrategy strategy = TimeBasedStrategyFactory.getStrategy(timeInput, taxiType);

            // 创建上下文并计算费用
            TaxiContext context = new TaxiContext();
            context.setStrategy(strategy);

            double price = context.calculateFare(distance);
            System.out.println("费用：" + price + "元");

        } catch (IllegalArgumentException e) {
            System.err.println("错误：" + e.getMessage());
        } finally {
            scanner.close();
        }
    }
}
